<?php
class Book extends Model
{
	public $id;
	public $name;
	
	public function __construct()
	{
		parent::__construct('books');
	}
	
	public function getAll()
	{
		$result = $this->selectAll($this->tableName);
		while($row = mysql_fetch_object($result, get_class()))
		{
			$books[] = $row;
		}
		return $books;
	}
	
	public function getByID($id)
	{
		$result = $this->selectByID($this->tableName, $id);
		return mysql_fetch_object($result, get_class());
	}
	
	/**
	 * 
	 * @param Book $book
	 */
	public function add($book)
	{
		$query = 'INSERT INTO books VALUES(\''  .$book->id  . '\', \'' . $book->name . '\')';
		$this->executeQuery($query);
	}
	
}